package com.quasar.hpatient.view.adapter;

import android.graphics.Color;
import android.text.TextPaint;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.custommodel.BloodPressureTableItem;
import com.quasar.hpatient.model.custommodel.RemindMedicineTableItem;
import com.quasar.hpatient.model.custommodel.TemperatureTableItem;
import com.quasar.hpatient.utils.Spanny;
import com.vise.log.ViseLog;

import java.util.List;

/**
 * author : 许建宏
 * Date: 2017/10/26 0026
 * View:血压adapter
 */

public class IntakeOutputAdapter extends BaseMultiItemQuickAdapter<TemperatureTableItem, BaseViewHolder> {

    public IntakeOutputAdapter(List<TemperatureTableItem> data) {
        super(data);
        addItemType(TemperatureTableItem.HEAD, R.layout.widget_test_show);
        addItemType(TemperatureTableItem.BODY, R.layout.widget_test_show);
        addItemType(TemperatureTableItem.TAIL, R.layout.widget_test_show);
    }

    @Override
    protected void convert(BaseViewHolder helper, TemperatureTableItem item) {
        Spanny spanny = new Spanny();
        switch (helper.getItemViewType()) {
            case TemperatureTableItem.HEAD:
                helper.setText(R.id.title, "时间");//检测时间
                helper.setText(R.id.msg, "项目");//检测时间
                StringBuffer stringBuffer = new StringBuffer();
                if (item.getDailyitemDose() != null) {
                    stringBuffer.append(item.getDailyitemDose());
                }
                helper.setText(R.id.msgcheck, stringBuffer.toString());//检测时间msgcheck

                helper.setText(R.id.demo, "状态");//检测时间
                break;

            case TemperatureTableItem.BODY:
                if(item.getLogTime()!=null && item.getLogTime().length()>0){
                    helper.setText(R.id.title, item.getLogTime().substring(5,16));//检测时间
                }else{
                    helper.setText(R.id.title, "");//检测时间
                }


                StringBuffer buffer=new StringBuffer();
                if(item.getMarkValues()!=null){
                    buffer.append(item.getMarkValues());
                }else{
                    buffer.append(item.getDailyitemName());
                }
                helper.setText(R.id.msg, buffer.toString());//检测项

                if (item.getDailyitemName().equals("出量")) {
                    helper.setText(R.id.msgcheck, item.getLogValue());//检测值
                } else {
                    helper.setText(R.id.msgcheck, item.getPaired());//检测值
                }

                TextView demo = helper.getView(R.id.demo);
                TextPaint tp = demo.getPaint();
                if (item.getStats().equals("0")) {
                    spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                } else {
                    spanny.append("危急值", new ForegroundColorSpan(color(R.color.red)));
                    tp.setFakeBoldText(true);
                }
                demo.setText(spanny);
                break;

            case TemperatureTableItem.TAIL:
                TextView SUMtitle = helper.getView(R.id.title);
                SUMtitle.setTextColor(color(R.color.btcolor));
                SUMtitle.setText(item.getLogTime());

                TextView SUMmsg = helper.getView(R.id.msg);
                SUMmsg.setText(item.getDailyitemName());
                SUMmsg.setTextColor(color(R.color.btcolor));

                ViseLog.d("检测值++++++" + item.getDailyitemName());
                TextView SUMmsgcheck = helper.getView(R.id.msgcheck);
                if (item.getDailyitemName() != null) {
                    if (item.getDailyitemName().contains("出量")) {
                        SUMmsgcheck.setText(item.getLogValue());
                    } else {
                        SUMmsgcheck.setText(item.getPaired());
                    }
                }

                SUMmsgcheck.setTextColor(color(R.color.btcolor));

                TextView demoSUM = helper.getView(R.id.demo);
                TextPaint tpSUM = demoSUM.getPaint();
                if (item.getStats().equals("0")) {
                    spanny.append("正常", new ForegroundColorSpan(color(R.color.btcolor)));
                } else {
                    spanny.append("危急值", new ForegroundColorSpan(color(R.color.red)));
                    tpSUM.setFakeBoldText(true);
                }
                demoSUM.setText(spanny);
                break;

        }

        helper.addOnClickListener(R.id.msg);//出量
        helper.addOnLongClickListener(R.id.msgcheck);//入量
        helper.addOnClickListener(R.id.msgcheck);//出量
        helper.addOnLongClickListener(R.id.msg);//入量
    }

    private int color(int value) {
        return MainAppliaction.getInstance().getResources().getColor(value);
    }
}
